package cn.z2huo.demo.spring.jdbc.dao;

import cn.z2huo.demo.model.dataobject.user.UserDO;
import lombok.RequiredArgsConstructor;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

/**
 * <p>
 *
 * @author z2huo
 */
@Repository
@RequiredArgsConstructor
public class UserDAO {

    private final JdbcTemplate jdbcTemplate;

    public UserDO getUserById(Long id) {

        String sql = """
                select * from z2huo_user
                where id = ?;
                """;

        return jdbcTemplate.queryForObject(sql, BeanPropertyRowMapper.newInstance(UserDO.class), id);
    }

}
